home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
ein
/
sources
/
cdpsrc.lzh
/
CDP
/
CDP.C
next >
Wrap
C/C++ Source or Header
|
1994-07-19
|
7KB
|
310 lines
/*<Header>==============================================================
*
* ébécâvâîü[âä / "CDP.C"
*
* [ EIN(tm) project : âTâôâvâïâvâìâOâëâÇ ]
*
* COPYRIGHT Nam 1994, All rights reserved.
*
* özòtüEægì₧üEëⁿò╧üEÅñùÿùpé╖é╫é─Ä⌐ùRüBé╜é╛é╡û│ò█Å╪é┴é╖
*
*-----------------------------------------------------------------------
* V1.0L01â┐ 94.04.07/Nam âvâìâgâ^âCâv
*</Header>==============================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <snd.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include <egb.h>
//#include <file_dlg.h>
//#include <tifflib.h>
#include <msdos.cf>
#include <loader.h>
#include <math.h>
#include <io.h>
#include <guidbg.h>
#include <wgb.h>
// üª é▒é▒é▄é┼é¬ò╜ï╧ôIé╔Ägùpé│éΩéΘâwâbâ_
#include <time.h>
#include <cdrfrb.h>
#include "..\ein\eintm.h" // EIN(TM)è╓ÿAâëâCâuâëâèé╠âwâbâ_
#define ERR_RETRY (10)
#define STD_CD_NO (0)
extern int updateCDdisp();
struct TIMEADRS tracktime[100], disctime, endtime;
int cdtype = -1; // ïNô«Ä₧ëëætcheckùp
int starttrack = 0;
int endtrack = 0;
int nowtrack = 0;
struct TIMEADRS trtime, dctime; // mphaseé┼ĵô╛
int clearCDstat()
{
register int i;
cdtype = -1;
nowtrack = -2;
endtrack = -2;
for (i=0; i<100; i++){
tracktime[i].min=0; // é▒éΩé═0âNâèâAé╡é╚éóé╞cdr_cdinfoé┼îδô«ì∞é╖éΘ(T-T)
tracktime[i].sec=0;
}
disctime.min=-2;
disctime.sec=-2;
trtime.min=-2;
trtime.sec=-2;
dctime.min=-2;
dctime.sec=-2;
return NOERR;
}
int getPlayStatus()
{
static int stat;
register int ret, retry;
// âèâgâëâCùLéΦ
for ( retry=0; retry<ERR_RETRY; retry++){
ret = cdr_mphase( STD_CD_NO, &stat, &nowtrack, &trtime, &dctime);
if ( ret==0 ){
break;
}
}
// éαé╡âGâëü[é╚éτ-1é≡ò╘é╖
if ( ret!=0 ){
clearCDstat();
return -1;
}
// ÆΓÄ~Æåé╚éτ0é≡ò╘é╖
if ( stat==0 ){
nowtrack=0;
return stat;
}
// ëëætÆåé╚éτï╚ö╘ìåé≡ò╘é╖
return nowtrack;
}
// CDé╠âXâeü[â^âXĵô╛
int readTOC()
{
register int ret, retry;
//é▄é╕CDé≡Ä~é▀éµéñ
cdr_mstop( STD_CD_NO );
// âèâgâëâCùLéΦ
for ( retry=0; retry<ERR_RETRY; retry++){
ret = cdr_cdinfo( STD_CD_NO, &cdtype, &starttrack, &endtrack,
&tracktime[0], &disctime );
if ( ret==0 ){
#ifdef DEBUG
printf(" error_retry(%d): cdr_cdinfo=%x\n", retry, ret);
#endif
break;
}
}
// ÅIù╣Ä₧è╘é═frame--
endtime = disctime;
if ( endtime.frame > 0 ){
endtime.frame--;
} else {
endtime.frame = 74;
if ( endtime.sec > 0 ){
endtime.sec--;
} else {
endtime.sec = 59;
endtime.min--;
}
}
#ifdef DEBUG
printf("### cdr_cdinfo: type:%d start:%d, end:%d (%2d.%2d.%2d)\n",
cdtype, starttrack, endtrack,
disctime.min, disctime.sec, disctime.frame);
#endif
/* ô╟é▌ĵéΦÄ₧é╔ERROR or âfü[â^é╠é▌é╠CD é╚éτé╬"Er"ò\Īé╔é╡é─ÅIù╣ */
if ( ret!=0 || cdtype==2 ){
updateCDdisp( 1 );
return NOERR;
}
return NOERR;
}
int func_Play()
{
register int ret, i, retry;
/* ëëætÅ≤æ╘é╠ĵô╛ */
ret = getPlayStatus();
// éαé╡ëëætÆåé╚éτ
if ( ret > 0 ){
// éαé╡ëëætÆåé╚éτÆΓÄ~
cdr_mstop( STD_CD_NO );
updateCDdisp( 1 );
clearCDstat();
return NOERR;
}
// éαé╡ÆΓÄ~Æåé╚éτCDé╠âXâeü[â^âXĵô╛
readTOC();
/* ì┼Åëé╠âIü[âfâBâIâgâëâbâNé≡ëëæt */
updateCDdisp( 1 );
for ( i=starttrack-1; i<endtrack; i++ ){
#ifdef DEBUG
printf("--> track %d: (%2d.%2d.%2d)-(%2d.%2d.%2d)\n", i,
tracktime[i].min, tracktime[i].sec, tracktime[i].frame,
endtime.min, endtime.sec, endtime.frame);
#endif
// âfü[â^âgâëâbâNé┼é╚é»éΩé╬ëëæt
if ( (tracktime[i].min & 0x80)==0 ){
// âèâgâëâCùLéΦ
for ( retry=0; retry<ERR_RETRY; retry++){
ret = cdr_mtrplay( STD_CD_NO, &tracktime[i], &endtime, 0 );
if ( ret==0 ){
break;
}
#ifdef DEBUG
printf(" error_retry(%d): cdr_mtrplay=%x\n", retry, ret);
#endif
}
updateCDdisp( 1 );
break;
}
}
return NOERR;
}
int func_Rev()
{
register int ret, i, retry;
/* ëëætÅ≤æ╘é╠ĵô╛ */
ret = getPlayStatus();
// ïNô«Ä₧è∙é╔ëëæté╡é─éóéΘé╚éτ, é▄é╕TOCé≡ô╟é▌ì₧é▐
if ( cdtype<0 ){
readTOC();
if (nowtrack<1){
nowtrack=1;
}
} else {
// éαé╡ÆΓÄ~Æåé╚éτplay
if ( ret<1 ){
func_Play();
return NOERR;
}
}
/* âfü[â^é╠é▌é╠CD é╚éτé╬"Er"ò\Īé╔é╡é─ÅIù╣ */
if ( cdtype==2 ){
updateCDdisp( 1 );
return NOERR;
}
// éαé╡ëëætÆåé╚éτêΩÄ₧ÆΓÄ~
ret = cdr_pause( STD_CD_NO );
/* æOé╠âIü[âfâBâIâgâëâbâNé≡ëëæt */
if ( (nowtrack > 1) && ((tracktime[starttrack].min & 0x80)==0) ){
i = nowtrack-1-1;
} else {
// î╗ì▌ê╩Æué¬èJÄnâgâëâbâNé┼èÄé┬âfü[â^âgâëâbâNé╚éτ
i = endtrack -1;
}
for ( ; i>=0; i-- ){
#ifdef DEBUG
printf("--> track %d: (%2d.%2d.%2d)-(%2d.%2d.%2d)\n", i,
tracktime[i].min, tracktime[i].sec, tracktime[i].frame,
endtime.min, endtime.sec, endtime.frame);
#endif
// âfü[â^âgâëâbâNé┼é╚é»éΩé╬ëëæt
if ( (tracktime[i].min & 0x80)==0 ){
// âèâgâëâCùLéΦ
for ( retry=0; retry<ERR_RETRY; retry++){
ret = cdr_mtrplay( STD_CD_NO, &tracktime[i], &endtime, 0 );
if ( ret==0 ){
break;
}
#ifdef DEBUG
printf(" error_retry(%d): cdr_mtrplay=%x\n", retry, ret);
#endif
}
updateCDdisp( 1 );
break;
}
}
return NOERR;
}
int func_FF()
{
register int ret, i, retry;
/* ëëætÅ≤æ╘é╠ĵô╛ */
ret = getPlayStatus();
// ïNô«Ä₧è∙é╔ëëæté╡é─éóéΘé╚éτ, é▄é╕TOCé≡ô╟é▌ì₧é▐
if ( cdtype<0 ){
readTOC();
if (nowtrack<1){
nowtrack=0;
}
} else {
// éαé╡ÆΓÄ~Æåé╚éτplay
if ( ret<1 ){
func_Play();
return NOERR;
}
}
/* âfü[â^é╠é▌é╠CD é╚éτé╬"Er"ò\Īé╔é╡é─ÅIù╣ */
if ( cdtype==2 ){
updateCDdisp( 1 );
return NOERR;
}
// éαé╡ëëætÆåé╚éτêΩÄ₧ÆΓÄ~
ret = cdr_pause( STD_CD_NO );
#ifdef DEBUG
printf("--> track %d endtrack:%d\n", nowtrack, endtrack);
#endif
/* ăé╠âIü[âfâBâIâgâëâbâNé≡ëëæt */
if ( (nowtrack < endtrack) && ((tracktime[endtrack].min & 0x80)==0) ){
i = nowtrack-1+1;
} else {
// î╗ì▌ê╩Æué¬ì┼ÅIâgâëâbâNé┼èÄé┬âfü[â^âgâëâbâNé╚éτ
i = starttrack -1;
}
for ( ; i<endtrack; i++ ){
#ifdef DEBUG
printf("--> track %d: (%2d.%2d.%2d)-(%2d.%2d.%2d)\n", i,
tracktime[i].min, tracktime[i].sec, tracktime[i].frame,
endtime.min, endtime.sec, endtime.frame);
#endif
// âfü[â^âgâëâbâNé┼é╚é»éΩé╬ëëæt
if ( (tracktime[i].min & 0x80)==0 ){
// âèâgâëâCùLéΦ
for ( retry=0; retry<ERR_RETRY; retry++){
ret = cdr_mtrplay( STD_CD_NO, &tracktime[i], &endtime, 0 );
if ( ret==0 ){
break;
}
#ifdef DEBUG
printf(" error_retry(%d): cdr_mtrplay=%x\n", retry, ret);
#endif
}
updateCDdisp( 1 );
break;
}
}
return NOERR;
}